day-21

ESS 330

Author

Nina Hayford

Load Libraries

library(dataRetrieval)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tsibble)
Registered S3 method overwritten by 'tsibble':
  method               from 
  as_tibble.grouped_df dplyr

Attaching package: 'tsibble'
The following objects are masked from 'package:base':

    intersect, setdiff, union
library(ggplot2)
library(plotly)

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
library(feasts)
Loading required package: fabletools
library(lubridate)

Attaching package: 'lubridate'
The following object is masked from 'package:tsibble':

    interval
The following objects are masked from 'package:base':

    date, intersect, setdiff, union

Download and Prepare Data

poudre_flow <- readNWISdv(siteNumber = "06752260",
                          parameterCd = "00060",
                          startDate = "2013-01-01",
                          endDate = "2023-12-31") |>
  renameNWISColumns() |>
  mutate(Date = yearmonth(Date)) |>
  group_by(Date) |>
  summarise(Flow = mean(Flow, na.rm = TRUE))
GET:https://waterservices.usgs.gov/nwis/dv/?site=06752260&format=waterml%2C1.1&ParameterCd=00060&StatCd=00003&startDT=2013-01-01&endDT=2023-12-31

Convert to tsibble

poudre_tsibble <- as_tsibble(poudre_flow, index = Date)

Plot Time Series

gg_time <- ggplot(poudre_tsibble, aes(x = Date, y = Flow)) +
  geom_line(color = "blue") +
  labs(title = "Monthly Mean Streamflow: Cache la Poudre River",
       x = "Date", y = "Flow (cfs)")

gg_time

# Animate with plotly
ggplotly(gg_time)

Subseries Plot

gg_subseries(poudre_tsibble, Flow)

Interpretation

The subseries plot shows how streamflow changes by month across years. Each line represents a year, and each facet represents a month, which helps visualize seasonal cycles. Typically, you’ll notice higher flows in spring/early summer and lower flows in late summer/fall. The “subseries” are the flow values for each month across the years, showing consistent seasonal peaks and troughs.